﻿using PoemGame.Domain.GameAggregate;
using PoemGame.Domain.PlayerAggregate;
using PoemGame.Domain.Seedwork;
using PoemGame.Domain.Services;

namespace PoemGame.ApplicationService
{
    /// <summary>
    /// 抢答模式
    /// First come first answer
    /// </summary>
    public class GamePlayFCFAService : GamePlayServiceBase, IDomainService
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameRepository"></param>
        /// <param name="playerRepository"></param>
        /// <param name="checkservicefactory"></param>
        /// <param name="_aftergameActionFactory"></param>
        public GamePlayFCFAService(IGameRepository gameRepository,
            IPlayerRepository playerRepository,
            IDomainServiceFactory<ICheckAnswerService> checkservicefactory) : base(gameRepository, playerRepository, checkservicefactory)
        {

        }
        /// <summary>
        /// 只在顺序作答有效
        /// </summary>
        /// <param name="player"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        protected async override Task<string> SetNextPlayer(Player player, Game game)
        {
            var curr=game.GetCurrentPlayer();
            if (curr != null) curr.PlayerStatus = PlayerGameStatus.Waiting;
            return await Task.FromResult("继续抢答");
        }
      


        /// <summary>
        /// 
        /// </summary>
        /// <param name="player"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public  override Task<GeneralResult> SetPlayer(Player player, Game game)
        {
            game.SetPlayerInturn(player.Id);
         
            return  Task.FromResult( new GeneralResult { IsSuccess=true , Message = $"{player.UserName}抢答成功，回答问题" });
        }


    }
}
